﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Agen.ServiceAgencyWPF;
using System.Diagnostics;
using System.Windows.Data;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace Agen.Models
{
    public class ApplicationManager
    {
        public const string CLICK_ON_CUSTOMER_HANDLE = "CLICK_ON_CUSTOMER_HANDLE";
        public const string CLICK_ON_MANAGE_CUSTOMER_BILLS_HANDLE = "CLICK_ON_MANAGE_CUSTOMER_BILLS_HANDLE";
        public const string CLICK_ON_MANAGE_CUSTOMER_CODE_HANDLE = "CLICK_ON_MANAGE_CUSTOMER_CODE_HANDLE";
         public const string CLICK_ON_MANAGE_CUSTOMER_OFFICIAL_EXAM_HANDLE = "CLICK_ON_MANAGE_CUSTOMER_OFFICIAL_EXAM_HANDLE";
        public const string PREVIOUS_HANDLE = "PREVIOUS_HANDLE";
        public const string CLICK_ON_ADD_CUSTOMER_HANDLE = "CLICK_ON_ADD_CUSTOMER_HANDLE";
        public const string CLICK_ON_MANAGE_CUSTOMER_SESSION_HANDLE = "CLICK_ON_MANAGE_CUSTOMER_SESSION_HANDLE";
        public const string NO_EMPLOYEE_HANDLE = "NO_EMPLOYEE_HANDLE";
        public const string USER_LIST_HANDLER = "USER_LIST_HANDLER";

        public const string URI_CUSTOMER_LIST = "/UserList";
        public const string URI_CUSTOMER_INFORMATIONS = "/User";
        public const string URI_CUSTOMER_MANAGE_CODE = "/ScoreCode";
        public const string URI_CUSTOMER_MANAGE_BILLS = "/Factures";
        public const string URI_CUSTOMER_MANAGE_OFFICAL_EXAM = "/OfficialExam";
        public const string URI_ADD_CUSTOMER = "/AddCustomer";
        public const string URI_ADD_CUSTOMER_TO_SESSION = "/AddCustomerToSession";
        public const string URI_LOGIN = "/LoginPage";

        public static Dictionary<string, string> URI_LABEL = new Dictionary<string, string>() {
            {URI_CUSTOMER_LIST, "Customer List"},
            {URI_CUSTOMER_INFORMATIONS, "User Information"},
            {URI_CUSTOMER_MANAGE_CODE, "Code"},
            {URI_CUSTOMER_MANAGE_BILLS, "Factures"},
            {URI_CUSTOMER_MANAGE_OFFICAL_EXAM, "Official Exam"},
            {URI_ADD_CUSTOMER, "Add customer"},
            {URI_ADD_CUSTOMER_TO_SESSION, "Add Customer to session"},
            {URI_LOGIN, "Connexion"}
        };

        public static Dictionary<string, string> EVENT_URI = new Dictionary<string, string>() {
            {CLICK_ON_CUSTOMER_HANDLE, URI_CUSTOMER_INFORMATIONS},
            {CLICK_ON_MANAGE_CUSTOMER_BILLS_HANDLE, URI_CUSTOMER_MANAGE_BILLS},
            {CLICK_ON_MANAGE_CUSTOMER_CODE_HANDLE, URI_CUSTOMER_MANAGE_CODE},
            {CLICK_ON_MANAGE_CUSTOMER_OFFICIAL_EXAM_HANDLE, URI_CUSTOMER_MANAGE_OFFICAL_EXAM},
            {CLICK_ON_ADD_CUSTOMER_HANDLE, URI_ADD_CUSTOMER},
            {CLICK_ON_MANAGE_CUSTOMER_SESSION_HANDLE, URI_ADD_CUSTOMER_TO_SESSION},
            {NO_EMPLOYEE_HANDLE, URI_LOGIN},
            {USER_LIST_HANDLER, URI_CUSTOMER_LIST}
        };

        public static Dictionary<string, string> URI_EVENT = new Dictionary<string, string>() {
            {URI_CUSTOMER_INFORMATIONS, CLICK_ON_CUSTOMER_HANDLE},
            {CLICK_ON_MANAGE_CUSTOMER_BILLS_HANDLE, CLICK_ON_MANAGE_CUSTOMER_CODE_HANDLE},
            {URI_CUSTOMER_MANAGE_CODE, URI_CUSTOMER_MANAGE_CODE},
            {URI_CUSTOMER_MANAGE_OFFICAL_EXAM, CLICK_ON_MANAGE_CUSTOMER_OFFICIAL_EXAM_HANDLE},
            {URI_ADD_CUSTOMER, CLICK_ON_ADD_CUSTOMER_HANDLE},
            {URI_ADD_CUSTOMER_TO_SESSION, CLICK_ON_MANAGE_CUSTOMER_SESSION_HANDLE},
            {URI_LOGIN, NO_EMPLOYEE_HANDLE},
            {URI_CUSTOMER_LIST, USER_LIST_HANDLER}
        };





        //Category
        public static Dictionary<int, string> Category = new Dictionary<int, string>() {
            {1, "M1"},
            {2, "M2"},
            {3, "M3"},
            {4, "A2"},
        };


        //Type
        public static Dictionary<int, string> Offer_Type_M1 = new Dictionary<int, string>() {
            {1, "Session"},
            {3, "Stage"}
        };

        public static Dictionary<int, string> Session_Type_M2 = new Dictionary<int, string>() {
            {4,"Session"},
            {5, "Stage"}
        };

        public static Dictionary<int, string> Session_Type_M3 = new Dictionary<int, string>() {
            {6, "Stage"}
        };
        public static Dictionary<int, string> Offer_Type_A2 = new Dictionary<int, string>() {
            {16, "Session"}
        };




        //SubType

        public static Dictionary<int, string> Offer_Stage_Type_M2 = new Dictionary<int, string>() {
            {7, "1 day on circuit"},
            {9, "1 week"}
        };

        public static Dictionary<int, string> Offer_Courses_Type_M2 = new Dictionary<int, string>() {
            {4, "curcuit"},
            {5, "traffic"}
        };

        public static Dictionary<int, string> Offer_Type_M3 = new Dictionary<int, string>() {
            {13, "Level 1"},
            {14, "Level 2"},
            {15, "Level 3"}
        };

        public static Dictionary<int, Dictionary<int, string>> itemsource_type = new Dictionary<int, Dictionary<int, string>>() {
            {1, Offer_Type_M1},
            {2, Session_Type_M2},
            {3, Session_Type_M3},
            {4, Offer_Type_A2},
        };

        public static Dictionary<int, Dictionary<int, string>> itemsource_subtype = new Dictionary<int, Dictionary<int, string>>() {
            {1, new Dictionary<int, string>()},
            {3, new Dictionary<int, string>()},
            {4, Offer_Courses_Type_M2},
            {5, Offer_Stage_Type_M2},
            {6, Offer_Type_M3},
            {16, new Dictionary<int, string>()}
        }; 


 


        public static string CURRENT_URI = "";
        public static string PREVIOUS_URI = "";

        public static List<string> applicationNavigation = new List<string>();


        public static CustomerDC CURRENT_CUSTOMER;

        public static AgencyEmployeeDC CURRENT_EMPLOYEE;


        public static event EventHandler<FrameEventArgs> FrameActionEventHandler;
        public static event EventHandler<ApplicationNavigationChangeEventArgs> ApplicationChangeNavigationActionEventHandler;

        public static AgencyServiceClient client = new AgencyServiceClient();

        public static void FrameAction(Object sender, string state, Object content ){
            if (state != PREVIOUS_HANDLE)
            {
                CURRENT_URI =EVENT_URI[state];
                if (applicationNavigation.Contains(EVENT_URI[state]))
                {
                    int index = 0;
                    foreach (string element in applicationNavigation)
                    {
                        if (element == EVENT_URI[state])
                        {
                            break;
                        }
                        index++;
                    }



                    applicationNavigation.RemoveRange(index+1, applicationNavigation.Count-(index+1));
                }
                else {
                    applicationNavigation.Add(EVENT_URI[state]);
                }
                
            }
            else {

                applicationNavigation.RemoveAt(applicationNavigation.Count-1);
                CURRENT_URI = applicationNavigation[applicationNavigation.Count-1];
            }
            Debug.WriteLine("DBG : APPLICATION_MANAGER => FrameAction, state = "+state);
            if (FrameActionEventHandler != null)
            {
                FrameActionEventHandler(sender, new FrameEventArgs());
            }
            
        }

       
    }

    public class FrameEventArgs : EventArgs
    {
        private string eventName;
        private Object content;
        public FrameEventArgs()
            : base()
        {

        }
    }


    public class ApplicationNavigationChangeEventArgs : EventArgs
    {
        private string eventName;
        private Object content;
        public ApplicationNavigationChangeEventArgs()
            : base()
        {
 
        }

    }

    public class BirthdateConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            DateTime dt = (DateTime)value;



            return dt.ToString("dd MMM, yyyy", culture);

        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            return value;

        }

    }

    public class ObtainConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string obtain= "Not Obtained";
            if(value is DateTime && value != null){
                obtain = "Obtained";
            }else{
                Boolean dt = (Boolean)value;
                if (dt)
                {
                    obtain = "Obtained";
                }
            }
            return obtain;

        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            throw new NotImplementedException();

        }

    }
    public class BoolNullConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool b = false;
            if(value != null){
                b = (bool)value;
            }
            return b;

        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            return value;

        }

    }

    public class DateNullConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DateTime b = DateTime.Now;
            if (value != null)
            {
                b = (DateTime)value;
            }
            return b;

        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            return value;

        }

    }

    public class DateNullBoolConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool r = false;
            if (value != null)
            {
                r = true;
            }
            return r;

        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            return value;

        }

    }

    public class LenghtBoolConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Boolean result = false;
            if((int)value > 0){
                result = true;
            }
            return result;
        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            return value;

        }

    }


    public class BeforeTodayVisibilityConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Visibility result = Visibility.Collapsed;
            if ((DateTime)value > DateTime.Now)
            {
                result = Visibility.Visible;
            }
            return result;
        }



        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            return value;

        }

    }


    


}
